package com.ocom.human.controller;


import com.ocom.common.constant.HumanServiceUrl;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.human.service.EcardRegCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@RestController
public class EcardController {

    @Autowired
    EcardRegCodeService ecardRegCodeService;

    @PostMapping(HumanServiceUrl.URLP_getEcardRegCode)
    public Result getEcardRegCode(Long companyId,Long pId){
        return ResultUtil.success(ecardRegCodeService.getCardInfo(companyId,pId));
    }

    @PostMapping(HumanServiceUrl.URLP_addEcardRegCode)
    public Result addEcardRegCode(Long companyId, Long pId, String regCode, String endTime) throws ParseException {
        DateFormat fmt =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = fmt.parse(endTime);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);//Date转换为Calendar
        cal.add(Calendar.DATE, 3);//将日期往后推3天，减少3天则-3. 月增加则Calendar.MONTH
        return ResultUtil.success(ecardRegCodeService.addEcardRegCode(companyId,pId,regCode, cal.getTime()));
    }



}
